<template>
  <div>
    <el-dialog title="数据更新" :visible.sync="showDialogGetters" :show-close="false">
      <el-form label-position="right" label-width="100px" :inline="true">
        <el-form-item v-for="filed in allFiled" :key="filed.prop" :label="filed.label">
          <el-select
            class="form-item"
            filterable
            v-if="filed.type==='select'"
            v-model="updateModelGetters[filed.prop]"
            :value="updateModelGetters[filed.prop]"
            :placeholder="updateModelGetters[filed.prop]">
            <el-option
              v-for="select in filed.select"
              :label="select.name"
              :value="select.id"
              :key="select.id">
            </el-option>
          </el-select>
          <el-date-picker
            class="form-item"
            v-else-if="filed.type==='date'"
            v-model="updateModelGetters[filed.prop]"
            type="date"
            value-format="yyyy-MM-dd"
            :placeholder="updateModelGetters[filed.prop]">
          </el-date-picker>
          <el-input v-else class="form-item" v-model="updateModelGetters[filed.prop]" :placeholder="updateModelGetters[filed.prop]"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitUpdate">确 定</el-button>
        <el-button @click="closeDialog">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {mapGetters, mapMutations} from 'vuex'

export default {
  name: 'cement-update',
  props: {
    allFiled: {
      type: Array
    }
  },
  methods: {
    ...mapMutations([
      'closeDialog'
    ]),
    submitUpdate () {
      this.$emit('submitUpdate')
    }
  },
  computed: {
    ...mapGetters([
      'showDialogGetters',
      'updateModelGetters'
    ])
  }
}
</script>

<style scoped>
  .form-item {
    width: 200px
  }
</style>
